package com.api.gbhg.luoao.la.util;

import java.util.HashMap;
import java.util.Map;

public class R {

    //是否成功
    private Boolean success;

    //返回码
    private Integer code;

    //返回消息
    private String message;

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object object) {
        this.data = object;
    }

    // 返回数据
    private Object data;

    //把构造方法私有   不让别人new该类
    private R() {}
    //实现链式编程
    //R.ok().code().message().data();

    //成功静态方法
    public static R ok() {
        R r = new R();
        r.setSuccess(true);
        r.setCode(200);
        r.setMessage("成功");
        return r;
    }

    //失败静态方法
    public static R error() {
        R r = new R();
        r.setSuccess(false);
        r.setCode(500);
        r.setMessage("失败");
        return r;
    }

    public R success(Boolean success){
        this.setSuccess(success);
        return this;   //返回this  实现链式编程
    }

    //实现链式编程
    //R.ok().code().message().data();
    
    public R message(String message){
        this.setMessage(message);
        return this;
    }

    public R code(Integer code){
        this.setCode(code);
        return this;
    }


    public R data(Map<String, Object> map){
        this.setData(map);
        return this;
    }
    public R data(Object object){
        this.setData(object);
        return this;
    }
}